package io2;

import java.io.*;

public class File2 {

    public static void main(String[] args) throws IOException {
        try (OutputStream os = new FileOutputStream("testDir/.c.txt");
             OutputStreamWriter osw = new OutputStreamWriter(os, "UTF-8");
             PrintWriter writer = new PrintWriter(osw)) {
            writer.println("LYL");
            writer.print("SSY");
            writer.printf("%d 黎雨琳孙诗语", 499+21);

            writer.flush();
        }
    }

    public static void main2(String[] args) throws IOException {
        try (OutputStream os = new FileOutputStream("testDir/c.txt")) {
            String s = "Li Yulin";
            byte[] bytes = s.getBytes();
            os.write(bytes);

            String ss = "\n黎雨琳";
            byte[] bytes1 = ss.getBytes("UTF-8");
            os.write(bytes1);
            os.flush();
        }
    }

    public static void main1(String[] args) throws IOException {
        try (OutputStream os = new FileOutputStream("testDir/c.txt")) {
            byte[] bytes = new byte[]{(byte) 'L', (byte) 'Y', (byte)'L'};
            os.write(bytes);
            os.write(bytes,0,1);
            os.flush();
        }
    }

    public static void main0(String[] args) {
        try (OutputStream os = new FileOutputStream("testDir/b.txt")) {
            os.write('l');
            os.write('i');
            os.write(' ');
            os.write('Y');
            os.write('u');
            os.write('l');
            os.write('i');
            os.write('n');

            os.flush();
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

}
